
{extend name=".././view/list.html" /}
{block name="jsset"}

{/block}
{block name="nav"}
	<span class="layui-breadcrumb">
		<a href="">荣誉管理</a>
		<a href="">荣誉册</a>
		<a><cite>荣誉列表</cite></a>
	</span>
{/block}
{block name="search"}
	<div class="layui-form-item">
      <label for="searchval" class="layui-form-label">
          关键字
      </label>
      <div class="layui-input-block">
          <input type="text" id="searchval" name="searchval"
          autocomplete="off" class="layui-input" placeholder="输入关键字并回车">
      </div>
    </div>
    <div class="layui-form-item">
	    <label for="subject_id" class="layui-form-label" style="height: 100%">所属学科</label>
	    <div class="layui-input-block">
	    	<input type="radio" name="subject_id" title="无" value="" lay-skin="primary" checked>
	    	{php}
	    		$sbj = new \app\teach\model\Subject;
	    		$subject = $sbj->field('id,title')->where('status',1)->order('paixu')->select();
	    	{/php}
	    	{volist name="subject" id="vo"}
	    		<input type="radio" name="subject_id" title="{$vo.title}" value="{$vo.id}" lay-skin="primary">
	    	{/volist}
	    </div>
	</div>
	<div class="layui-form-item" style="margin-bottom: 0;">
	    <label for="hjschool_id" class="layui-form-label" style="height: 100%">获奖单位</label>
	    <div class="layui-input-block">
	    	<input type="radio" name="hjschool_id" title="无" value="" lay-skin="primary" checked>
	    	{php} $school = danweiJibie('校级','区级'); {/php}
	    	{volist name="school" id="vo"}
	    		<input type="radio" name="hjschool_id" title="{$vo.jiancheng}" value="{$vo.id}" lay-skin="primary">
	    	{/volist}
	    </div>
	</div>
	<input type="hidden" name="rongyuce_id" value="{$list.rongyuce_id}">
{/block}
{block name="table"}
	<table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
{/block}
{block name="myjs"}
	<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-danger" lay-event="dels">
			<i class="iconfont">&#xe69d;</i> 批量删除
		</button>
		<button class="layui-btn" lay-event="add">
			<i class="iconfont">&#xe6b9;</i> 添加
		</button>
		<button class="layui-btn" lay-event="download">
			<i class="iconfont">&#xe714;</i> 下载
		</button>
	</div>
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
	<a class="layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon">&#xe642;</i></a>
	<a class="layui-btn-xs" lay-event="del" title="删除"><i class="layui-icon">&#xe640;</i></a>
</script>
<!-- 表格操作 -->
<script>
	// 设置列
  options.cols=[[ //表头
			{type:'checkbox', fixed: 'left'},
			{field: 'title', title: '荣誉名称',sort: true, minWidth:240},
			{field: 'bianhao', title: '获奖编号', minWidth:140,sort: true},
			{title: '获奖人', minWidth:120,templet:function(d){
				var str='';
				if(d.hjJsry)
				{
          for (var k = 0, length = d.hjJsry.length; k < length; k++) {
						if(k == 0){
							str = d.hjJsry[k].teacher.xingming;
						}else{
							str =str+'、'+d.hjJsry[k].teacher.xingming;
						}
					}
				}
				return str;
			}},
			{title: '参与人', minWidth:120,templet:function(d){
				var str='';
				if(d.cyJsry)
				{
					for (var k = 0; k < d.cyJsry.length; k++) {
						if(d.cyJsry[k].teacher){
							if(k == 0){
								str = d.cyJsry[k].teacher.xingming;
							}else{
								str =str+'、'+d.cyJsry[k].teacher.xingming;
							}
						}
					}
				}
				return str;
			}},
			{field: "subject_id",title: '所属学科',minWidth:120,sort: true,templet:function(d){
				var str='';
				if(d.rySubject)
				{
					str = d.rySubject.title;
				}
				return str;
			}},
			{field: "jiangxiang_id",title: '奖项', minWidth:120,sort: true,templet:function(d){
				var str='';
				if(d.jxCategory)
				{
					str = d.jxCategory.title;
				}
				return str;
			}},
			{field: 'hjshijian', title: '获奖时间',minWidth:120, sort: true},
			{field: 'status', title: '状态', minWidth:80,templet:'#status', sort: true},
			{field: 'id', title: '操作',toolbar: '#barDemo',minWidth:140}
		]];

  // 提交搜索条件后重载表格
    layui.use(['table','cjgl'],function(){
      var table = layui.table
          cjgl = layui.cjgl;
      //表头工具栏事件
      table.on('toolbar(mytable)', function(obj){
        switch(obj.event){
          case 'dels':
            var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值
            cjgl.delAll(checkStatus,'/rongyu/jsryinfo/delete','mytable');
            break;
          case 'add':
            cjgl.add('添加荣誉','/rongyu/jsryinfo/create/'+"{$list.rongyuce_id}",'','',true);
            break;
          case 'download':
          	window.open('/rongyu/jsryinfo/outxlsx/'+"{$list.rongyuce_id}");
            break;
        };
      });

      //监听行工具条
      table.on('tool(mytable)', function(obj){
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        switch(layEvent){
          	case 'del':// 删除
	          cjgl.del(obj,"/rongyu/jsryinfo/delete");
	          break;
	        case 'edit':// 编辑
	          cjgl.add('编辑荣誉','/rongyu/jsryinfo/edit/'+obj.data.id,'','',true);
	          break;
        };
      });
    });
</script>
{/block}
